package org.fing.edu.uy.esbadp.core.utils;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

public class JMXManager {
	
	public static Object callOperation(String jmxServiceURL, String mBeanName, String OperationName, Object[] arguments, String[] signature) throws Exception {
        JMXServiceURL service = new JMXServiceURL(jmxServiceURL);
        JMXConnector connector = JMXConnectorFactory.connect(service);
        MBeanServerConnection mbeanServer = connector.getMBeanServerConnection();
        ObjectName objectName = new ObjectName(mBeanName);
        Object object = mbeanServer.invoke(objectName, OperationName, arguments, signature);
        connector.close();
        return object;
	}

}
